package com.situ.ssm.controller;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.ssm.common.ServerResponse;
import com.situ.ssm.entity.Student;
import com.situ.ssm.service.IStudentService;

@Controller
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private IStudentService studentService;
	
	
	@RequestMapping("/getStudentListPage")
	public String getStudentListPage() {
		return "student_list";
	}
	
	@RequestMapping("/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Student student) {
		return studentService.pageList(page,limit,student);
	}
	
	@RequestMapping("/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return studentService.deleteById(id);
	}
	
	@RequestMapping("/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(Integer[] ids) {
		System.out.println(Arrays.toString(ids));
		return studentService.deleteAll(ids);
	}
	

	@RequestMapping("/getInsertPage")
	public String getInsertPage() {
		return "student_insert";
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public ServerResponse insert(Student student) {
		return studentService.insert(student);
	}
	
	@RequestMapping("/toUpdate")
	public String toUpdate(Integer id,Model model) {
		Student student = studentService.selectById(id);
		model.addAttribute("student", student);
		return "student_update";
	}
	
	@RequestMapping("/updateById")
	@ResponseBody
	public ServerResponse updateById(Student student) {
		return studentService.updateById(student);
	}
}
